package com.itcast.discover.Controller;

import com.itcast.discover.service.DiscoverService;
import com.pojo.discover.dto.DiscoverDto;
import com.pojo.discover.pojo.Discover;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/*
* 发现控制器
* */
@RestController
public class DiscoverController {
    @Autowired
    private DiscoverService discoverService;

    /*
    * 按条件分页查询发现推文
    * */
    @PostMapping("/discover/page1")
    public ResponseEntity<List<Discover>> findDiscoverByPage1(
           @RequestParam(value = "page",defaultValue = "1") Integer page,
           @RequestParam(value = "rows",defaultValue = "20") Integer rows,
           @RequestBody Discover discover
    ){
        List<Discover> discoverList=  discoverService. findDiscoverByPage(page,rows,discover);
        return ResponseEntity.ok().body(discoverList);
    }

    /*
    *查看具体发现信息
    * */
    @PostMapping("/discover/page")
    public List<Discover> findDiscoverByPage(
            @RequestParam(value = "page",defaultValue = "1") Integer page,
            @RequestParam(value = "rows",defaultValue = "20") Integer rows,
            @RequestBody(required = false) Discover discover
    ){
        List<Discover> discoverList=  discoverService. findDiscoverByPage(page,rows,discover);
        return discoverList;
    }


    /*
    * 查看发现信息
    * */
    @GetMapping("/discover/find")
    public DiscoverDto findDiscoverById(@RequestParam("id") Integer id){
        DiscoverDto discoverDto= discoverService.findDiscoverById(id);
        return discoverDto;
    }

}
